package hk.m4s.carfriends.presenter;

import android.content.Context;

import com.google.gson.Gson;

import hk.m4s.carfriends.AppConf;
import hk.m4s.carfriends.base.BasePresneterImpl;
import hk.m4s.carfriends.constract.INews;
import hk.m4s.carfriends.model.Datas;
import hk.m4s.carfriends.utils.CacheUtil;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/12/5.
 */

public class NewsPresenterImpl extends BasePresneterImpl implements INews.presenter
{
    private INews.Views mViews;
    private Gson mGson;
    private CacheUtil mUtil;

    public NewsPresenterImpl(Context context, INews.Views views)
    {
        mViews = views;
        mUtil = CacheUtil.get(context);
        mGson = new Gson();
    }

    @Override
    public void loadingDatasFromNet()
    {

    }

    @Override
    public void loadingDatasFromCache()
    {
        if (mUtil.getAsJSONObject(AppConf.NEWS) != null)
        {
            Datas datas = mGson.fromJson(mUtil.getAsJSONObject(AppConf.NEWS).toString(), Datas.class);
            mViews.showInfo(datas.getResult().getData());
        }
    }
}
